home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 470 < prev    next >
Encoding:
Text File  |  1996-08-06  |  1.8 KB  |  79 lines

  1. Path: engnews1.Eng.Sun.COM!taumet!clamage
  2. From: erikoest@idt.unit.no (Erik Oestlyngen)
  3. Newsgroups: comp.std.c++
  4. Subject: Type conflicts
  5. Date: 23 Feb 1996 19:45:00 GMT
  6. Organization: Norwegian University of Science and Technology
  7. Sender: erikoest@pil.idt.unit.no
  8. Approved: clamage@eng.sun.com (comp.std.c++)
  9. Message-ID: <ye7bumpal7p.fsf@pil.idt.unit.no>
  10. NNTP-Posting-Host: taumet.eng.sun.com
  11. X-Nntp-Posting-Host: pil.idt.unit.no
  12. X-Newsreader: Gnus v5.0.4
  13. Originator: clamage@taumet
  14.  
  15. Hi.
  16.  
  17. I'm doing working with a project trying to make a model for namespace
  18. structure of C++ programs, and make a visualization of it. (by the
  19. way, does anyone know of any interesting stuff on the net in this
  20. context ?)
  21.  
  22. Anyhow, i've got this little problem:
  23.  
  24. When i define two different structs with the same name in two
  25. different files, my compiler don't complain. I can then use the struct
  26. as input parameter for a function in one file, and from the other send
  27. the different struct into the function. The function will then get
  28. an other input type than it expects.
  29.  
  30. What does the ansi-C++ standard say about this?
  31.  
  32.  
  33. Example:
  34. ========
  35.  
  36. File1:
  37.  
  38. struct a {
  39.  int x;
  40. };
  41.  
  42. extern void f(struct a);
  43.  
  44. void main(void)
  45. {
  46.  struct a str;
  47.  
  48.  str.x=1;
  49.  
  50.  f(str);
  51. }
  52.  
  53. ---------------------
  54.  
  55. File2:
  56.  
  57. struct a {
  58.  long x;
  59. };
  60.  
  61. void f(struct a astr)
  62. {
  63.   astr.x+=2;    // crash, bang, crunch
  64. }
  65.  
  66. -- 
  67. --Erik Oestlyngen
  68.  
  69. ---------------------------------------------------------------
  70. erikoest@idt.unit.no      URL http://www.idt.unit.no/~erikoest/
  71.  
  72.  
  73. [ To submit articles: Try just posting with your newsreader.
  74.               If that fails, use mailto:std-c++@ncar.ucar.edu
  75.   FAQ:    http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  76.   Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  77.   Comments? mailto:std-c++-request@ncar.ucar.edu
  78. ]
  79.